package com.dtguai.app.common.error;

import java.util.HashMap;
import java.util.Map;

/**
 * 错误码定义类
 * <p>
 * 1000 - 9999 为系统错误码
 *
 * @author guo
 */
public enum ErrorCode {
    /**
     * 系统错误定义
     */
    NO_ERROR(200, "成功"),
    INTERNAL_SERVER_ERROR(500, "服务器错误,请联系管理员"),
    BAD_REQUEST(400, "参数有误"),
    TOKEN_VALIDATE_ERROR(401, "无效的token"),
    TOKEN_EXPIRED(402, "token过期"),
    NOT_FOUND(404, "路径不存在，请检查路径是否正确"),
    REPETITION(405, "记录重复"),
    NOT_PERMISSION(406, "没有权限，请联系管理员授权"),
    NOT_PERMISSION_ADD_ROLE_NOT_CREATE(407, "新增用户所选角色，不是本人创建"),
    ADMIN_NOT_DELETE(408, "系统管理员不能删除"),
    NOT_DELETE(409, "当前用户不能删除"),
    NOT_SYS_MENU_DELETE(410, "系统菜单，不能删除"),
    NOT_SYS_MENU_DELETE_SUBMENU(411, "请先删除子菜单或按钮"),
    ID_LOCK(412, "账号已被锁定,请联系管理员"),
    SCHEDULE_ERROR(413, "定时任务异常"),
    HTTP_REQUEST_METHOD_NOT_SUPPORTED(414, "请查看api注意get/post等提交方式"),
    OSS_ERROR(430, "OSS异常"),


    /**
     * 错误码定义类
     * 1000 - 9999 为模块错误码
     */

    SYSTEM_UNKNOWN_ERROR(1000, "系统未知错误."),
    REQUEST_PARAMS_INVALID(1001, "请求参数非法."),
    REQUEST_DECRYPT_FAIL(1002, "请求解密错误."),
    REQUEST_API_IS_NULL(1003, "请求接口为空"),
    REQUEST_NOT_AUTH(1004, "用户未登陆"),
    REQUEST_SIGN_INVALID(1005, "Sign校验失败"),
    REQUEST_PARAMS_NULL(1006, "请求参数为空."),
    REQUEST_PARAMS_UID_IS_NULL(1007, "uid参数为空."),
    PROTOCOL_IS_NULL(1010, "Protocol为空."),
    SECRET_KEY_LENGTH_WRONG(1011, "密钥长度不对."),
    USER_NOT_EXIST(1012, "用户不存在"),
    USER_ALREADY_EXIST(1013, "用户已经存在"),
    PHONE_ALREADY_EXIST(1014, "用户手机号已注册"),
    USER_NEED_LOGIN(1015, "用户需要登陆"),
    USER_SECRET_EXPIRE(1016, "秘钥过期"),
    DATE_FORMAT_ERROR(1017, "日期格式转换错误"),
    LEJANE_APPID_IS_ABSENT(1018, "APP_ID[{}]不存在"),
    REQUEST_TOKEN_EXPIRED(1019, "请求token过期"),
    IMEI_IN_BLACKLIST(1020, "黑名单设备"),
    CREATE_TOKEN_ERROR(1021, "创建token失败"),
    ID_NOT_NULL(1022, "id不能为空"),
    NAME_PASSWORD_ERROR(1023, "账号或密码不正确"),


    /**
     * 功能模块错误码定义
     */

    /**
     * 10000 - 10099 用户模块错误码
     */
    USER_NOT_EXIST_ERROR(10001, "用户名密码错误"),
    USER_PASSWORD_ERROR(10002, "密码错误"),
    USER_MOBILE_REPETITION(10003, "手机号重复"),
    USER_OLD_PASSWORD_ERROR(10004, "原密码不正确"),


    ;

    ErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private int code;
    private String message;

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }


    private static Map<Integer, ErrorCode> errorMap = new HashMap<>();

    static {
        for (ErrorCode pec : ErrorCode.values()) {
            if (errorMap.containsKey(pec.code)) {
                throw new RuntimeException("error code[" + pec.code + "] ------com.guo.web.common.errorCode.ErrorCode");
            }
            errorMap.put(pec.getCode(), pec);
        }
    }

}
